#include <p24FJ64GA102.h>
#include "LED.h"

#define HW_LED_1_SET LATBbits.LATB15
#define HW_LED_2_SET LATBbits.LATB14
#define HW_LED_3_SET LATBbits.LATB13

#define HW_LED_1_GET PORTBbits.RB15
#define HW_LED_2_GET PORTBbits.RB14
#define HW_LED_3_GET PORTBbits.RB13

#define HW_LED_ON 1
#define HW_LED_OFF 0

static LedFlags Leds_get(void);
static void Leds_set(LedFlags flags);

LedFunctions Leds = {
	Leds_get,
	Leds_set
};

static LedFlags Leds_get(void) {
	LedFlags flags = LED_NONE;

	flags |= (HW_LED_1_GET == HW_LED_ON ? LED_1 : LED_NONE);
	flags |= (HW_LED_2_GET == HW_LED_ON ? LED_2 : LED_NONE);
	flags |= (HW_LED_3_GET == HW_LED_ON ? LED_3 : LED_NONE);

	return flags;
}

static void Leds_set(LedFlags flags) {
	HW_LED_1_SET = (flags & LED_1 ? HW_LED_ON : HW_LED_OFF);
	HW_LED_2_SET = (flags & LED_2 ? HW_LED_ON : HW_LED_OFF);
	HW_LED_3_SET = (flags & LED_3 ? HW_LED_ON : HW_LED_OFF);
}
